import request from '@/api/request';
import store from '@/store/index';
import router from '@/router/index';

// 查询相应卡口的详细信息
export function InquiryCrossing(data) {
    return request({
        url: 'InquiryCrossing',
        method: 'post',
        data: data
    });
}

function getMenuItem() {
    let routes = store.state.menu.routes;
    let path = router.currentRoute.path;
    let menuItem = null;
    routes.map(item => {
        if (path == item.path) {
            menuItem = item;
        } else {
            item.children && item.children.map(r => {
                if (path == r.path) {
                    menuItem = r;
                }
            });
        }
    });
    return menuItem;
}

// 公共布控中心加站点显示
export function PublicCenterSite(data) {

    let menuItem = getMenuItem();
    if (menuItem) {
        data.menu_id = menuItem.id ? menuItem.id : menuItem.pid;
    }

    return request({
        url: 'PublicCenterSite',
        method: 'post',
        data: data
    });
}

// 公共布控中心显示
export function ShowPublicCenter(data) {
    let menuItem = getMenuItem();
    if (menuItem) {
        data.menu_id = menuItem.id;
    }

    return request({
        url: 'ShowPublicCenter',
        method: 'post',
        data: data
    });
}

// 字典分组查询
export function DictionariesGroup(data) {
    return request({
        url: 'DictionariesGroup',
        method: 'post',
        data: data
    });
}

// 字典分组查询
export function getRouters(data) {
    return request({
        url: 'Menu0',
        method: 'post',
        data: data
    });
}
